from logger import logger

from config import parser as config
from config import RRcfgparser as parser
import defs
import rabbyt

logger.debug("Imported stuff for unit module successfully.")

class Unit:
	def __init__(self, name):
		self.name = name
		self.hp = config.getint(name, "hp")
		self.maxhp = config.getint(name, "hp")
		self.speed = config.getint(name, "speed")
		self.displayname = config.get(name, "name")
		self.info = config.get(name, "info")
		self.sprite = rabbyt.Sprite(config.get(name, "sprite"))
		
		self.sprite.alpha = 0.7 # not selected
		
		self.wx = 0
		self.wy = 0
#		self.proj = None
		self.bounding_radius = config.getint(name, "radius")
		
		self.selected = False
	def copy(self):
		return Unit(self.name)
	def reproject(self, cam):
		self.sprite.x = (self.wx - cam.x) * cam.zoom
		self.sprite.y = (self.wy - cam.y) * cam.zoom
		self.x, self.y = self.sprite.x, self.sprite.y
		self.sprite.scale = cam.zoom
#		if not self.proj == [self.x, self.y]:
#			logger.debug("World x: " + str(self.wx))
#			logger.debug("World y: " + str(self.wy))
#			logger.debug("Cam x: " + str(cam.x))
#			logger.debug("Cam y: " + str(cam.y))
#			logger.debug("Sprite x: " + str(self.sprite.x))
#			logger.debug("Sprite y: " + str(self.sprite.y))
#			self.proj = [self.x, self.y]

	def draw(self, cam):
		self.reproject(cam)
		self.sprite.render()
